#pragma once

#include <Windows.h>

#include "Types.h"



class Timer
{
public:

	typedef MemMgr::T_U32 LowPrecision;
	typedef MemMgr::T_U64 HighPrecision;

	Timer();

	void Start(void);

	LowPrecision TimeElapsedSec(void) const;
	LowPrecision TimeElapsedMilliSec(void) const;
	HighPrecision TimeElapsedMicroSec(void) const;

private:

	HighPrecision mStart;
	HighPrecision mFreq;
};



inline Timer::Timer()
{
	Start();
}

inline void Timer::Start()
{
	QueryPerformanceFrequency(reinterpret_cast<LARGE_INTEGER*>(&mFreq));
	QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&mStart));
}

inline Timer::LowPrecision Timer::TimeElapsedSec() const
{
	HighPrecision end;
	QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&end));
	const HighPrecision diff = ((end - mStart) * 1) / mFreq;
	const LowPrecision microseconds = static_cast<LowPrecision>(diff & 0xffffffff);
}

inline Timer::LowPrecision Timer::TimeElapsedMilliSec() const
{
	HighPrecision end;
	QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&end));
	const HighPrecision diff = ((end - mStart) * 1000) / mFreq;
	const LowPrecision microseconds = static_cast<LowPrecision>(diff & 0xffffffff);
	return microseconds;
}

inline Timer::HighPrecision Timer::TimeElapsedMicroSec() const
{
	HighPrecision end;
	QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&end));
	return ((end - mStart) * 1000000) / mFreq;
}
